
require "game/ui/form/blacksmith/UIDemonStatue"

-- 魔神雕像
function initDemonStatue(self)
    self.item:removeAllChildren();

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            local pos = self.gridData:getPos();

            -- 打开工坊界面
            if UIMgr.getCurrentScene():isOpen("UIDemonStatue") then
                UIMgr.getCurrentScene():removeFormByName("UIDemonStatue");
            end
            local uiDemonStatue = UIDemonStatue.create(pos);
            UIMgr.getCurrentScene():addForm(uiDemonStatue);
            -- 音效
            AudioM.playFx("workshop_store");
        end
    end

    -- 工坊图标
    local class = self.gridData.classify;
    local data = DemonStatueM.queryStatue(class, 1);
    local icon = data["icon"] or "demon_statue";
    icon = getLevelItemIconPath(icon);

    self.icon = ccui.ImageView:create(icon);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end
